<?php

$q = isset($_GET['q']) ? intval($_GET['q']) : '';

if ( empty($q) ) {
  echo "请选择一个网站";
  exit();
}

$servername = "127.0.0.1:3306";
$username = "root";
$password = "zyenongqaz1";
$dbname = "my_db";
$con = mysqli_connect($servername,$username,$password ,$dbname);

if (!$con) {
  die("数据库连接失败".mysqli_error($con));
}

$sql="SELECT * FROM Websites WHERE id = '".$q."'";
$result = $con->query($sql);


echo "<table border='1'>
<tr>
<th>ID</th>
<th>网站名</th>
<th>网站 URL</th>
<th>Alexa 排名</th>
<th>国家</th>
</tr>";

while($row = mysqli_fetch_array($result)){
    echo "<tr>";
    echo "<td>" . $row['id'] . "</td>";
    echo "<td>" . $row['name'] . "</td>";
    echo "<td>" . $row['url'] . "</td>";
    echo "<td>" . $row['alexa'] . "</td>";
    echo "<td>" . $row['country'] . "</td>";
    echo "</tr>";
}

echo "</table>";
 
mysqli_close($con);
?>